<?php
//生成数字验证码图片
header("Content-type:text/html;charset=utf-8");
//定义系统路径
define("ROOT_PATH", str_replace("\\","/",dirname(__FILE__)));

//sission设置
//设置一个存放目录
$savePath = ROOT_PATH."/../session_save/";
//保存12小时
$lifeTime = 43200;//保存12小时 (12 * 3600)
//保存路径
session_save_path($savePath);
//生命周期
session_set_cookie_params($lifeTime);
session_start();

/**
 * 纯数字
 */
function numCode(){
	$authnum="";
	srand((double)microtime()*1000000);
	$im = imagecreate(55,25);
	$black = ImageColorAllocate($im, 0,0,0);
	$white = ImageColorAllocate($im, 255,255,255);
	$gray = ImageColorAllocate($im, 200,200,200);
	imagefill($im,0,0,$white);
	$authnum = rand(10000,99999);

	//将四位整数验证码绘入图片
	imagestring($im, 6, 6, 6, $authnum, $black);


	for($i=0;$i<200;$i++)   //加入干扰象素
	{
	    $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
	    imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
	}
	header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");
	header("Content-type: image/PNG;charset=utf-8");
	ImagePNG($im);
	ImageDestroy($im);
	return $authnum;
}

@$_SESSION["i_code"]=numCode();
?>